﻿package {
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.net.*;
	import flash.utils.*;

	/**
	 * Main demo
	 * @author wilson
	 */
	public class Main extends Sprite {
		
		var CDXML:XML;
		var xmlLoader:URLLoader = new URLLoader;

		public function Main():void {
			if (stage) {
				init();
			} else {
				addEventListener(Event.ADDED_TO_STAGE, init);
			}
			
			var xml:URLRequest=new URLRequest("CDCategory.xml");

			xmlLoader.addEventListener(Event.ADDED_TO_STAGE,clickButton);   //COMPLETE --->ADDED_TO_STAGE no Error#1034
			xmlLoader.load(xml);

		}
		
		private function init(e:Event = null):void {
			// set stage property 設計舞台屬性
			this.stage.align = StageAlign.TOP_LEFT;
			this.stage.scaleMode = StageScaleMode.NO_SCALE;
			this.stage.stageWidth = 640;
			this.stage.stageHeight = 80;

			// test component
			m_texBoard = new TextInfoBoard();
			addChild(m_texBoard);

			// simulate as a button
			m_button = new Sprite();
			m_button.graphics.beginFill(0xFF0000);
			m_button.graphics.drawRect(0,200, 100, 100);
			m_button.graphics.endFill();
			m_button.addEventListener(MouseEvent.CLICK, clickButton);
			m_button.x = 400;
			m_button.y = 50;
			addChild(m_button);
			

		}
		private function clickButton(e:MouseEvent):void {
			// add a string to show on screen
			//m_texBoard.addShow("a new line" + m_count + "\n" );
			CDXML = XML(xmlLoader.data);
			m_texBoard.addShow("標題:"+ CDXML.CD.TITLE[m_count]+"\n");
			m_texBoard.addShow("演出者:"+ CDXML.CD.ARTIST[m_count]+"\n");
			m_texBoard.addShow("國家:" + CDXML.CD.COUNTRY[m_count]+"\n");
			m_texBoard.addShow("出版:"+ CDXML.CD.COMPANY[m_count]+"\n");
			m_texBoard.addShow("價格:"+ CDXML.CD.PRICE[m_count]+"\n");
			m_texBoard.addShow("年代:"+ CDXML.CD.YEAR[m_count]+"\n");
			m_texBoard.addShow("\n");
			
			m_count++;

		}
		private var m_button:Sprite;
		private static  var m_count:int = 0;
		private var m_texBoard:TextInfoBoard;
	}
}